import $web3js from "../web3.js";
import $erc20Token from "../erc20Token/index.js";

const contractInfo = require("./swapMiningContract.json");

let web3 = $web3js.getWeb3();
let contractAddress = "";

let contractConst = {
  contract: web3 ? new web3.eth.Contract(contractInfo.abi, contractAddress) : ""
};
const getSwapMiningAddress = () => {
  return contractAddress;
};

const getSwapMiningContract = () => {
  return contractConst.contract;
};

const getSwapMiningQuantity = async (
  outputToken,
  outputAmount,
  anchorToken
) => {
  outputAmount = await $erc20Token.toErc20TokenValue(outputAmount, outputToken);
  // console.log(outputToken)
  // console.log(outputAmount)
  // console.log(anchorToken)
  return $web3js.commonCallAndHandlerParams(
    getSwapMiningContract().methods.getQuantity,
    $erc20Token.fromErc20TokenValue,
    [anchorToken],
    outputToken,
    outputAmount,
    anchorToken
  );
  // return $web3js.commonCallAndHandler(getSwapMiningContract().methods.getQuantity, $web3js.fromWei, outputToken, outputAmount, anchorToken);
  // return $web3js.commonCall(getSwapMiningContract().methods.getQuantity, outputToken, outputAmount, anchorToken);
};

export default {
  getSwapMiningAddress,
  getSwapMiningContract,
  getSwapMiningQuantity
};
